package com.weikuang.fareast.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.trello.rxlifecycle2.android.ActivityEvent;
import com.weikuang.fareast.R;
import com.weikuang.fareast.adapter.AddQueryDetailsAdapter;
import com.weikuang.fareast.bean.ChangeBean;
import com.weikuang.fareast.bean.Count1Bean;
import com.weikuang.fareast.bean.CountDetailBean;
import com.weikuang.fareast.http.MainHttp;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.dlc.commonlibrary.okgo.rx.OkObserver;
import cn.dlc.commonlibrary.ui.widget.TitleBar;
import cn.dlc.commonlibrary.utils.ToastUtil;
import cn.dlc.commonlibrary.utils.rv_tool.RecyclerViewUtil;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

//录入订单详情

public class AddQueryDetailsActivity extends BaseActivity {

    AddQueryDetailsAdapter mStatisticsAdapter;

    @BindView(R.id.mRecyclerView)
    RecyclerView mRecyclerView;

    @BindView(R.id.mTitleBar)
    TitleBar mTitleBar;


    String order_id = "";

    Count1Bean.DataBean data;

    private CountDetailBean mCountDetailBean;
    List<ChangeBean> datasList = new ArrayList<>();
    @Override
    protected int getLayoutId() {
        return R.layout.activity_add_query_details;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_query_details);
        ButterKnife.bind(this);
        InitRecyclerView();
        data = (Count1Bean.DataBean)getIntent().getSerializableExtra("data");
        if (data != null){
            order_id = data.id;
            countDetail(data.id);
        }
    }


    private void InitRecyclerView() {
        mStatisticsAdapter = new AddQueryDetailsAdapter();
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        mRecyclerView.setLayoutManager(linearLayoutManager);
        RecyclerViewUtil.setDefaultDivider(mRecyclerView, linearLayoutManager);
        mRecyclerView.setAdapter(mStatisticsAdapter);

    }





    private void countDetail(String orderId) {
        MainHttp.get().countDetail(orderId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .compose(bindUntilEvent(ActivityEvent.DESTROY))
                .subscribe(new OkObserver<CountDetailBean>() {
                    @Override
                    public void onSuccess(CountDetailBean hotelBean) {
                        showOneToast(hotelBean.msg);
                        mCountDetailBean = hotelBean;
                        for (CountDetailBean.DataBean bean : hotelBean.data) {
                            ChangeBean statisticsBean = new ChangeBean(bean.title, bean.title, Integer.parseInt(bean.amount),Integer.parseInt(bean.check),Integer.parseInt( bean.bad), Integer.parseInt(bean.back), bean.id);
                            datasList.add(statisticsBean);
                        }
                        mStatisticsAdapter.setNewData(datasList);
                    }

                    @Override
                    public void onFailure(String message, Throwable tr) {
                        ToastUtil.show(getActivity(), message);
                    }
                });
    }





}
